<?php
/**
 * @copyright meila.com
 * @author wangtao5@
 * @name 发布接口
 * @param
 *         $nick = 作用
 *
 *
 */
include('../../__global.php');
include(SERVER_ROOT_PATH.'/include/config/dataRule/ml_datarule_album.php');
class aj_albumfeed extends ml_controller
{
    //执行默认检查的参数集合
    protected  $_param_check = array(
            'album_id' => array('type'=>ML_DATATYPE_DIGIT, 'is_must'=>true),
            'sort' => array('type'=>ML_DATATYPE_INARRAY,'in'=>array('new', 'hot')),
    );
    //错误描述
    protected  $_error_msg = array(
            'album_id' => 'album_id',
            'sort'=>'sort',
    );
    private $_sort_array = array('new'=>'ctime', 'hot'=>'reply_cnt');
    private $_page;
    private $_uid;
    /**
     * 初始化参数
     */
    function initParam()
    {
        //必选项
        $this->_option['album_id'] = Tool_input::input('album_id', 'G', '');
        $this->_page = (int)Tool_input::input('page', 'G', 1);
        $this->_page = $this->_page<1 ? 1 : $this->_page;
        $this->_option['sort'] = Tool_input::input('sort','G','new');
        $this->_uid = $this->__visitor['uid'];
    }
    
    /**
     * @develop_template
     * 检查参数合法性
     */
    function checkParam()
    {
        $this->check_option();
    }
    
    /**
     * @develop_template
     * 核心业务逻辑
     */
    function main(){
        $data = $this->get_list();
        if(!$data)
            $this->api_output(ML_RCODE_HACK);
        $this->api_output(ML_RCODE_SUCC, $data);
    }
    
    function get_list(){
        $start = ($this->_page-1)*ML_ALBUM_ALBUMFEED_PAGE;
        $oRdsCount = new ml_model_rdsCount();
        $count = $oRdsCount->getAlbumfeedCnt($this->_option['album_id']);
        if(false === $count)
            return false;
        if($count>0 && $start<$count){
            $oAlbumfeed = new ml_model_album_dbAlbumfeed();
            $rs = $oAlbumfeed->get_list_by_album_id($this->_option['album_id'],$start,ML_ALBUM_ALBUMFEED_PAGE, $this->_sort_array[$this->_option['sort']].' desc');
            if(!$rs)
                return false;
            $list = $oAlbumfeed->get_data();
            $option['uid'] = $this->_uid;
            $option['data'] = $list;
            $bizFeed = new ml_biz_feed_albumfeed();
            $bizFeed->initParam($option);
            $list = $bizFeed->create_html();
        }else{
            $list = array();
        }
        
        return array('list'=>$list, 'count'=>$count);
    }
}

new aj_albumfeed();
